<template>
    <div class="sidebar">
        <el-menu
            class="sidebar-el-menu"
            :default-active="onRoutes"
            :collapse="collapse"
            background-color="#324157"
            text-color="#bfcbd9"
            active-text-color="#20a0ff"
            unique-opened
            router
        >
            <div class="tit"></div>
            <template v-for="item in items">
                <template v-if="item.subs">
                    <el-submenu :index="item.index" :key="item.index">
                        <template slot="title">
                            <i :class="item.icon"></i>
                            <span slot="title">{{ item.title }}</span>
                        </template>
                        <template v-for="subItem in item.subs">
                            <el-submenu
                                v-if="subItem.subs"
                                :index="subItem.index"
                                :key="subItem.index"
                            >
                                <template slot="title">{{ subItem.title }}</template>
                                <el-menu-item
                                    v-for="(threeItem,i) in subItem.subs"
                                    :key="i"
                                    :index="threeItem.index"
                                >{{ threeItem.title }}</el-menu-item>
                            </el-submenu>
                            <el-menu-item
                                v-else
                                :index="subItem.index"
                                :key="subItem.index"
                            >{{ subItem.title }}</el-menu-item>
                        </template>
                    </el-submenu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.index" :key="item.index">
                        <i :class="item.icon"></i>
                        <span slot="title">{{ item.title }}</span>
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script>

export default {
    data() {
        return {
            collapse: false,
            items: [
                {
                    icon: 'el-icon-monitor',
                    index: 'jcjla',
                    title: '数据总览'
                },
                {
                    icon: 'el-icon-star-off',
                    index: 'haha3',
                    title: '管理人员管理',
                    subs: [
                        {
                            index: 'editor',
                            title: '管理人员查看'
                        },
                        {
                            index: 'i18n',
                            title: '管理人员添加'
                        }
                    ]
                },
                {
                    icon: 'el-icon-user-solid',
                    index: 'haha2',
                    title: '劳务人员管理',
                    subs: [
                        {
                            index: 'form',
                            title: '员工管理'
                        },

                        {
                            index: 'addform',
                            title: '添加员工'
                        }
                    ]
                },
                {
                    icon: 'el-icon-scissors',
                    index: 'editor',
                    title: '人员风险管理',
                    subs: [
                        {
                            index: 'addpart',
                            title: '行为记录'
                        },
                        // {
                        //     index: 'upload',
                        //     title: '添加行为'
                        // },
                        {
                            index: 'depart',
                            title: '行为类型'
                        }
                    ]
                },

                {
                    icon: 'el-icon-date',
                    index: 'form',
                    title: '部门档案管理',
                    subs: [
                        {
                            index: 'permission',
                            title: '部门管理'
                        }
                    ]
                },
                {
                    icon: 'el-icon-takeaway-box',
                    index: 'icon2',
                    title: '分包单位管理',
                    subs: [
                        {
                            index: 'worktype',
                            title: '工种管理'
                        }
                    ]
                }
            ]
        };
    },
    methods: {},
    computed: {
        onRoutes() {
            return this.$route.path.replace('/', '');
        }
    },
    created() {
        var me = this;
        window.addEventListener('setItem', () => {
            var newVal = sessionStorage.getItem('luyou');
            // console.log(newVal);
            if (newVal == 5) {
                me.items = [
                    {
                        icon: 'el-icon-monitor',
                        index: 'hjall',
                        title: '数据总览'
                    },
                    {
                        icon: 'el-icon-date',
                        index: 'jindugl',
                        title: '进度管理'
                    },
                    {
                        icon: 'el-icon-date',
                        index: 'lssj',
                        title: '历史数据'
                    }
                ];
            }
            if (newVal == 4) {
                me.items = [
                    {
                        icon: 'el-icon-monitor',
                        index: 'jdall',
                        title: '数据总览'
                    },
                    {
                        icon: 'el-icon-date',
                        index: 'jindugl',
                        title: '进度管理'
                    }
                ];
            }
            if (newVal == 2) {
                me.items = [
                    {
                        icon: 'el-icon-monitor',
                        index: 'dataall',
                        title: '数据总览'
                    },
                    {
                        icon: 'el-icon-date',
                        index: 'wentilx',
                        title: '安全隐患类型'
                    },
                    {
                        icon: 'el-icon-date',
                        index: 'addpart2',
                        title: '问题排查',
                        subs: [
                            {
                                index: 'wentied',
                                title: '已整改'
                            },
                            {
                                index: 'wentiing',
                                title: '未整改'
                            }
                        ]
                    }
                ];
            }
            if (newVal == 3) {
                me.items = [
                    {
                        icon: 'el-icon-monitor',
                        index: 'zlall',
                        title: '数据总览'
                    },
                    {
                        icon: 'el-icon-monitor',
                        index: 'jcjl',
                        title: '检查记录'
                    },
                    {
                        icon: 'el-icon-monitor',
                        index: 'zmgz',
                        title: '检查记录'
                    },
                    {
                        icon: 'el-icon-monitor',
                        index: 'zlyh',
                        title: '质量隐患类型'
                    },

                    {
                        icon: 'el-icon-date',
                        index: 'form',
                        title: '质量问题审批',
                        subs: [
                            {
                                index: 'jcjla',
                                title: '未整改'
                            },
                            {
                                index: 'jcjlb',
                                title: '已整改'
                            },
                            {
                                index: 'jcjlc',
                                title: '整改待验'
                            }
                        ]
                    },
                    {
                        icon: 'el-icon-monitor',
                        index: 'tongzs',
                        title: '整改通知书'
                    },
                    {
                        icon: 'el-icon-monitor',
                        index: 'fadan',
                        title: '处罚单'
                    }
                ];
            }
            if (newVal == 1) {
                me.items = [
                    {
                        icon: 'el-icon-monitor',
                        index: 'jcjla',
                        title: '数据总览'
                    },
                    {
                        icon: 'el-icon-star-off',
                        index: 'haha3',
                        title: '管理人员管理',
                        subs: [
                            {
                                index: 'editor',
                                title: '管理人员查看'
                            },
                            {
                                index: 'i18n',
                                title: '管理人员添加'
                            }
                        ]
                    },
                    {
                        icon: 'el-icon-user-solid',
                        index: 'haha2',
                        title: '劳务人员管理',
                        subs: [
                            {
                                index: 'form',
                                title: '员工管理'
                            },

                            {
                                index: 'addform',
                                title: '添加员工'
                            }
                        ]
                    },

                    {
                        icon: 'el-icon-scissors',
                        index: 'editor3',
                        title: '人员风险管理',
                        subs: [
                            {
                                index: 'addpart',
                                title: '行为记录'
                            },
                            // {
                            //     index: 'upload',
                            //     title: '添加行为'
                            // },
                            {
                                index: 'depart',
                                title: '行为类型'
                            }
                        ]
                    },

                    {
                        icon: 'el-icon-date',
                        index: 'form',
                        title: '部门档案管理',
                        subs: [
                            {
                                index: 'permission',
                                title: '部门管理'
                            }
                        ]
                    },
                    {
                        icon: 'el-icon-takeaway-box',
                        index: 'icon2',
                        title: '分包单位管理',
                        subs: [
                            {
                                index: 'worktype',
                                title: '工种管理'
                            },
                            {
                                index: 'fbdw',
                                title: '分包单位'
                            }
                        ]
                    }
                ];
            }
        });
    }
};
</script>

<style scoped>
.tit {
    width: 200px;
    height: 50px;
    background: rgb(50, 65, 87);
}

.sidebar {
    display: none;
    position: absolute;
    left: 0;
    top: 100px;
    bottom: 0;
    overflow-y: scroll;
}

.sidebar::-webkit-scrollbar {
    width: 0;
}

.sidebar-el-menu:not(.el-menu--collapse) {
    width: 200px;
}

.sidebar > ul {
    height: 100%;
}
</style>
